package com.wyp168.leetcode;

/**
 * @ClassName MaxAscendingSum
 * @Title TODO leetcode-- 1800: 最大子数组和
 * @Description
 * @Author wyp168
 * @Date 2022/10/7 14:18
 */
public class MaxAscendingSumSolution {
    public static void main(String[] args) {
        MaxAscendingSumSolution solution = new MaxAscendingSumSolution();
        int[] nums = {100,10,1};
        System.out.println(solution.maxAscendingSum(nums));
    }

    public int maxAscendingSum(int[] nums) {
        //记录最大的子数组和
        int maxSum = nums[0];
        int tempSum = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] < nums[i]) {
                tempSum += nums[i];
            } else {
                tempSum = nums[i];
            }
            if (tempSum > maxSum) {
                maxSum = tempSum;
            }
        }
        return maxSum;
    }
}
